package cn.java68.zj.printer;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@Aspect
public class PrinterAop {
    @Around("within(cn.java68.zj.printer..*)")
    public Object huanrao(ProceedingJoinPoint jp)throws  Throwable{
        long start=System.nanoTime();
        Object o=jp.proceed();
        long end=System.nanoTime();
        System.out.println(jp.getTarget().getClass().getName()+"对象的方法:"+jp.getSignature().getName()+"耗时"+(end-start)+"纳秒");
        return o;
    }
    @Before("within(cn.java68.zj.printer..*)")
    public void before(JoinPoint jp){
        System.out.println("方法:"+jp.getSignature().getName()+"开始于"+new Date());
    }
}
